package Hot100.DP;

import java.util.Stack;

public class numSquares {
    public static void main(String[] args) {
        System.out.println(new numSquares().numSquares(12));
    }
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        int max = Integer.MAX_VALUE;
        for (int i = 0; i <= n; i++) {
            dp[i] = max;
        }
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j * j <= i; j++) {
                dp[i] = Math.min(dp[i - j * j] + 1,dp[i]);
            }
        }
        return dp[n];
    }
}
